﻿Imports System.Data.SqlClient
Public Class frm_doimk

    Private Sub cmd_doi_Click(sender As Object, e As EventArgs) Handles cmd_doi.Click
        If StrComp(txt_mkmoi.Text, txt_nhaplaiMK.Text) <> 0 Then
            MsgBox("Nhập lại mật khẩu không đúng")
            Exit Sub
        End If

        Dim cmd As New SqlCommand("sp_DoiMatKhau", conn)
        cmd.CommandType = CommandType.StoredProcedure

        cmd.Parameters.AddWithValue("@taikhoan", dangnhap)
        cmd.Parameters.AddWithValue("@matkhaucu", txt_mkcu.Text)
        cmd.Parameters.AddWithValue("@matkhaumoi", txt_mkmoi.Text)

        Dim i As Integer = cmd.ExecuteNonQuery
        If i < 0 Then
            lbthongbao.Text = "Xảy ra lỗi, Chưa đổi được mật khẩu"
        ElseIf i > 0 Then
            lbthongbao.Text = "Đổi mật khẩu thành công!"
            txt_mkcu.Clear()
            txt_mkmoi.Clear()
            txt_nhaplaiMK.Clear()
            txt_mkcu.Focus()
        End If
    End Sub

    Private Sub cmd_huybo_Click(sender As Object, e As EventArgs) Handles cmd_huybo.Click
        For Each k As Control In Me.Controls
            If TypeOf k Is TextBox Then
                k.Text = ""
                txt_mkcu.Focus()
            End If
        Next
    End Sub

    Private Sub frm_doimk_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
    Private Sub chk_hienthiKT_CheckedChanged(sender As Object, e As EventArgs) Handles chk_hienthiKT.CheckedChanged
        If chk_hienthiKT.CheckState = CheckState.Checked Then '1
            txt_mkcu.PasswordChar = ""
            txt_mkmoi.PasswordChar = ""
            txt_nhaplaiMK.PasswordChar = ""
        Else
            txt_mkcu.PasswordChar = "*"
            txt_mkmoi.PasswordChar = "*"
            txt_nhaplaiMK.PasswordChar = "*"
        End If
    End Sub
End Class